package server;

import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Stack;


public class MyClassLoader  extends ClassLoader {
    /**
     * 加载指定类路径下指定文件名
     * @param
     */
    @Override
    protected Class<?> findClass(String name) {
        String myPath = "file:///Users/zjy/Documents/WorkSpace/LagouClass/HomeWork/webapps/demo1/server/" + name.replace(".","/") + ".class";
        System.out.println(myPath);
        byte[] cLassBytes = null;
        Path path = null;
        try {
            path = Paths.get(new URI(myPath));
            cLassBytes = Files.readAllBytes(path);
        } catch (IOException | URISyntaxException e) {
            e.printStackTrace();
        }
        Class clazz = defineClass( cLassBytes, 0, cLassBytes.length);
        return clazz;
    }

}
